﻿using System;
using System.Collections.Generic;
using System.Text;
using AspNetCs.IDAL;
using AspNetCs.DALFactory;
using AspNetCs.Model;
using System.Data;
using AspNetCs.Common;
namespace AspNetCs.Bll
{
    public class SacrificeList
    {
        ISacrificeList CreateBll = Conn.CreateSacrificeList();

        public int Add(SacrificeList_Model md)
        {
            if (md == null) return -1;
            return CreateBll.Add(md);
        }
        public SacrificeList_Model GetModel(DataRow dr)
        {
            return CreateBll.GetModel(dr);
        }
        public SacrificeList_Model GetModel(int id)
        {
            SacrificeList_Model m = new SacrificeList_Model();
            DataTable dt = GetDataTable(" id=" + id);
            foreach (DataRow dr in dt.Rows)
            {
                m = GetModel(dr);
            }
            return m;
        }
        public DataTable GetDataTable(string filter)
        {
            return CreateBll.GetDataTable(filter);
        }
        public DataTable GetDataTable(int PageSize, int pageindex, string filter)
        {
            return CreateBll.GetDataTable(PageSize, pageindex, filter);
        }
        public int GetReDataRecord(string filter)
        {
            return CreateBll.GetReDataRecord(filter);
        }
        /// <summary>
        /// 祭祀用户点数扣除
        /// </summary>
        /// <param name="Classid"></param>
        /// <param name="Readme"></param>
        /// <param name="Userid"></param>
        /// <returns></returns>
        public int SaCrificePoint(int Classid, string Readme, int Userid)
        {
            int Result = 0;
            try
            {
                Users_Model UserMd = Users_Bll.CreatNew.GetModel(Userid);
                int d = 0;
                switch (Classid)
                {
                    case 0://音乐
                        d = System_Lable.SystemGetCache.MusicPoint;
                        Readme += "点歌扣出点数" + d + "点";
                        break;
                    case 3://上香
                        d = System_Lable.SystemGetCache.Incense;
                        Readme += "上香扣出点数" + d + "点";
                        break;
                    case 4://献花
                        d = System_Lable.SystemGetCache.Flower;
                        Readme += "献花扣出点数" + d + "点";
                        break;
                    case 5://点烛
                        d = System_Lable.SystemGetCache.candlePoint;
                        Readme += "点烛扣出点数" + d + "点";
                        break;
                    case 6://敬酒
                        d = System_Lable.SystemGetCache.drinkPoint;
                        Readme += "敬酒扣出点数" + d + "点";
                        break;
                    case 7://贡品
                        d = System_Lable.SystemGetCache.tributePoint;
                        Readme += "贡品扣出点数" + d + "点";
                        break;
                    case 8://叩拜
                        d = System_Lable.SystemGetCache.kowtowedPoint;
                        Readme += "叩拜扣出点数" + d + "点";
                        break;
                    case 9://超度
                        d = System_Lable.SystemGetCache.releasePoint;
                        Readme += "超度扣出点数" + d + "点";
                        break;
                }
                Point_Log_Model M = new Point_Log_Model();
                M.Addtime = DateTime.Now;
                M.NetIp = StringHelper.Ip();
                M.Point = d;
                M.Readme = Readme;
                M.UserId = Userid;
                if (d > 0)
                {

                    if (UserMd.Point >= d)
                    {
                        Result = Point_Log_Bll.CreateNew.Add(M);
                    }
                    else
                    {
                        Result = 0;
                    }
                }
                else
                {
                    Result = 1;
                }
            }
            catch
            {
                Result = 0;
            }
            return Result;
        }





    }
}
